package org.atlantis.sbe

/**
 * 如果将此文件命名为package.scala，那么此包下的其他类就可以自动导入该package object下
 * 的所有内容。即此包下的其他类会默认导入org.atlantis.sbe.server.package._。
 *
 * Scala中的package object的实现方式其实就是Java中的静态内部类，比如此package object会被编译成：
 * <code>
 * public final class package {
 * 		public static interface Headers {
 * 			Option get(String key);
 * 			...
 * 		}
 * }
 * </code>
 */
package object server {

    trait Headers {
        def get(key: String): Option[String] = getAll(key).headOption
        def apply(key: String): String = get(key).getOrElse(scala.sys.error("Header doesn't exist"))
        def getAll(key: String): Seq[String]
    }

    case class Cookie(name: String, value: String, maxAge: Int = -1, path: String = "/", domain: Option[String] = None,
        secure: Boolean = false, httpOnly: Boolean = true)

    trait Cookies {
        def get(name: String): Option[Cookie]
        def apply(name: String): Cookie
    }
}